package vn.edu.saigontech.ncms.model.teaching;

import java.util.Date;

import javax.persistence.*;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.model.info.Offering;
import vn.edu.saigontech.ncms.model.info.Teacher;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_video_schedule")
@SuppressWarnings("serial")
public class VideoSchedule extends BaseEntity {

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "offering_id", nullable = false)
	private Offering offering;

	@Temporal(TemporalType.DATE)
	@Column(name = "date")
	private Date date;

	@Column(name = "video")
	private String video;

	@Column(name = "lesson")
	private String lesson;

	@Column(name = "comment", length = 4000)
	private String comment;

	public int getVideoNumber() {
		int ret = 0;
		try {
			char cValue = this.video.charAt(this.video.length() - 1);
			ret = Integer.parseInt(cValue + "");
		} catch (NumberFormatException e) {
			ret = 0;
		}
		return ret;
	}
	
	public Teacher getTeacher() {
		return offering.getTeacher(date);
	}

	public Offering getOffering() {
		return offering;
	}

	public void setOffering(Offering offering) {
		this.offering = offering;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getVideo() {
		return video;
	}

	public void setVideo(String video) {
		this.video = video;
	}

	public String getLesson() {
		return lesson;
	}

	public void setLesson(String lesson) {
		this.lesson = lesson;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
}